package com.ljwy.gun;

import android.content.Context;
import android.database.DataSetObserver;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SpinnerAdapter;
import android.widget.TextView;


import com.ljwy.gun.bean.AcInfo;
import com.ljwy.gun.bean.CpInfo;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class CpSpinnerAdapter implements SpinnerAdapter {
    private Context context;
    private List<CpInfo.DataBean> datas;

    public CpSpinnerAdapter(Context context, List<CpInfo.DataBean> datas) {
        this.context = context;
        this.datas = datas;
    }

    @Override
    public View getDropDownView(int i, View view, ViewGroup viewGroup) {

        ViewHolder viewHolder = null;
        if (view == null) {
            view = View.inflate(context, R.layout.adapter_get_view, null);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        CpInfo.DataBean info = datas.get(i);
        viewHolder.tvgetView.setText(String.format("%s", info.getName()));
        return view;
    }

    @Override
    public void registerDataSetObserver(DataSetObserver dataSetObserver) {

    }

    @Override
    public void unregisterDataSetObserver(DataSetObserver dataSetObserver) {

    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public CpInfo.DataBean getItem(int i) {
        return datas.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder = null;
        if (view == null) {
            view = View.inflate(context, R.layout.adapter_get_view, null);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        CpInfo.DataBean info = datas.get(i);
        viewHolder.tvgetView.setText(String.format("%s", info.getName()));
        return view;
    }

    @Override
    public int getItemViewType(int i) {
        return 0;
    }

    @Override
    public int getViewTypeCount() {
        return 1;
    }

    @Override
    public boolean isEmpty() {
        return false;
    }

    static
    class ViewHolder {
        @BindView(R.id.tvgetView)
        TextView tvgetView;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
